package cn.joyfulmedia.common.log;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.LayoutBase;

/**
 * 自定义日志格式
 *
 * @author yujun
 * @create 2016-11-08 19:21
 */
public class CustomLogLayout extends LayoutBase<ILoggingEvent> {

    /**
     * Transform an event (of type Object) and return it as a String after
     * appropriate formatting.
     * <p>
     * <p>Taking in an object and returning a String is the least sophisticated
     * way of formatting events. However, it is remarkably CPU-effective.
     * </p>
     *
     * @param event The event to format
     * @return the event formatted as a String
     */
    @Override
    public String doLayout(ILoggingEvent event) {
        StringBuffer sb = new StringBuffer(128);
        if (event.getLevel().levelInt == Level.INFO.levelInt) {
            sb.append("[0]").append("[]").append(event.getFormattedMessage());
        }
        return sb.toString();
    }
}
